package com.acce.gxsc.page.supervision.carInMarket;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;

import com.acce.gxsc.R;
import com.acce.gxsc.page.supervision.carInMarket.child.CarInMarketChildFragment;
import com.acce.sdk.base.mvp.BaseMvpActivity;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by huxley on 2017/5/26.
 */

public class CarInMarketActivity extends BaseMvpActivity<CarInMarketView, CarInMarketPresenter> implements CarInMarketView {

    @Bind(R.id.tabs)
    TabLayout    mTabs;
    @Bind(R.id.viewpager)
    ViewPager    mViewpager;

    @Override
    protected CarInMarketPresenter createPresenter() {
        return new CarInMarketPresenter();
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.car_in_market_activity);
        ButterKnife.bind(this);
        init();
    }

    private void init() {
        Adapter adapter = new Adapter(getSupportFragmentManager());
        adapter.addFragment("10", "1号门私人柜");
        adapter.addFragment("20", "1号门月结柜");
        adapter.addFragment("30", "新区内");
        adapter.addFragment("40", "小新场");
        adapter.addFragment("50", "农园棚");
        adapter.addFragment("60","其他区域");
        mViewpager.setAdapter(adapter);
        mTabs.setupWithViewPager(mViewpager);
        mViewpager.setOffscreenPageLimit(5);
    }

    private static class Adapter extends FragmentPagerAdapter {
        private final List<CarInMarketChildFragment> mFragments      = new ArrayList<>();
        private final List<String>                   mFragmentTitles = new ArrayList<>();

        private Adapter(FragmentManager fm) {
            super(fm);
        }

        private void addFragment(String queryType, String title) {
            mFragments.add(CarInMarketChildFragment.newInstance(queryType));
            mFragmentTitles.add(title);
        }

        @Override
        public CarInMarketChildFragment getItem(int position) {
            return mFragments.get(position);
        }

        @Override
        public int getCount() {
            return mFragments.size();
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return mFragmentTitles.get(position);
        }
    }
}
